<?php
/**
 * SEO管理页面
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: SeoController.class.php v1.0 2014-06-12 17:27:03 $
 */
namespace Admin\Controller;
class SeoController extends CommonController{
    public function _initialize() {
        parent::_initialize();
    }
    
    /**
     * 搜索引擎登录
     */
    public function engine(){
        $this->display();
    }
    
    public function sitemaps() {
        $act = I("post.act", "");
        $msg = '<div style="padding:30px 0 0 10px;"><a href="/Data/sitemap.xml" target="_blank" class="btn lsn">地图生成成功！查看/Data/sitemap.xml</a></div>';
        if($act == 'xml'){
            $list = M('Content')->field('id,title,pubdate')->order('id desc')->limit(10000)->select();
            $sitemap = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\r\n";
            foreach($list as $k=>$v){
                $sitemap .= "<url>\r\n"."<loc>".U('Home/View/index',array('aid'=>$v['id']))."</loc>\r\n"
                        ."<priority>0.6</priority>\r\n<lastmod>".date('Y-m-d',$v['pubdate'])."</lastmod>\r\n<changefreq>weekly</changefreq>\r\n</url>\r\n";
            }
            $sitemap .= '</urlset>';
            
            $file = fopen(YDCMS_DATA . "sitemap.xml","w");
            fwrite($file, $sitemap);
            fclose($file);
           
            return $this->successReturn($msg);
        }else if($act == "html"){
            //$msg = '<div style="padding:30px 0 0 10px;"><a href="/Data/sitemap.xml" target="_blank" class="btn lsn">地图生成成功！查看/Data/rssmap.xml</a></div>';
            return $this->successReturn($msg);
        }else{
            $this->display();
        }
    }
}
